-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: Ensure that fill_na in Categorical only replaces null values #27932
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
BUG: Ensure that fill_na in Categorical only replaces null values #27932
Conversation
pandas/tests/series/test_missing.py
Outdated
], | ||
) | ||
def test_fillna_categorical_with_new_categories( | ||
self, new_categories, fill_value, expected_output |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you need new_categories
at all? Can you not create the series with categories=['a', 'b', 'c', 'd', 'e']
?
Can you add a test where the original series and the fill_value series have the same categories, but in different order?
s = pd.Series(pd.Categorical(['a', None, 'b'], categories=['b', 'c', 'a']))
s.fillna(pd.Series(pd.Categorical(['a', 'c', 'a'], categories=['c', 'a', 'b']))
…e fill value series values are in different order
ad111b6
to
e088eab
Compare
Can you add the test from #27932 (comment)? We've had issues in the past with unordered categories where the categories / codes didn't line up. |
…er to categories of origin series
Sure :) I've added a test where the fill value is a series with the same categories as the original series but in a different order, sorry for having missed this the first time |
5b0e307
to
c089c45
Compare
c089c45
to
a679508
Compare
Looks great @MarcoGorelli. Thanks! |
… only replaces null values
fillna
using columns of dtypecategory
also fills non-NaN values #26215black pandas
git diff upstream/master -u -- "*.py" | flake8 --diff